package com.example.dsplatform.Controller;

import cn.hutool.core.util.StrUtil;
import com.example.dsplatform.Service.LoginService;

import com.example.dsplatform.pojo.Entity.ResponseResult;
import com.example.dsplatform.pojo.Entity.User;
import com.example.dsplatform.utls.StringUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.web.bind.annotation.*;

/**
 * @author wdx3004
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
@ApiOperation(value = "登录接口")
public class UserController {

    @Autowired
    private LoginService loginServcie;

    @PostMapping(value = "/login")
    @ApiOperation(value = "实现登录功能")
    public ResponseResult login(@RequestBody User user) {
        String arg1 = user.getId();
        String arg2 = user.getPassword();
        String arg3 = user.getId();
        if (StrUtil.isBlank(arg1) && StrUtil.isBlank(arg2)) {
            return new ResponseResult<>(205,"输入参数错误，请重新输入");
        } else if (StrUtil.isBlank(arg3) && StrUtil.isBlank(arg2)) {
            return new ResponseResult<>(205,"输入参数错误，请重新输入");
        }
        else{
            return loginServcie.login(user);
        }
    }

    @PostMapping(value = "/register")
    @ApiOperation(value = "实现激活功能")
    public ResponseResult Active(@RequestBody User user) {
        return loginServcie.active(user);
    }

    /*@PostMapping(value = "/loginbyphone")
    @ApiOperation(value = "实现登录功能")
    public ResponseResult loginByPhone(@RequestBody User user) {
        return loginServcie.login(user);
    }
*/
    @GetMapping(value = "/loginout")
    @ApiOperation(value = "实现登出功能")
    public ResponseResult loginout() {
        return loginServcie.loginout();
    }

    @PostMapping(value = "/setPassword")
    @ApiOperation(value = "添加手机号")
    public ResponseResult setPassword(@RequestBody User user) {
        return loginServcie.setPassword(user);
    }



}

